package com.zhp.farmerclient.controller;

import com.zhp.farmerclient.common.Result;
import com.zhp.farmerclient.entity.Survey;
import com.zhp.farmerclient.service.SurveyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/suggest")
@CrossOrigin//解决前端后端跨域问题
public class SurveyController {

    @Autowired
    public SurveyService surveyService;

    //意见反馈
    @PostMapping("/explain")
    public Result suggest(@RequestBody Survey survey){
        return surveyService.suggest(survey);
    }

    //删除
    @PostMapping("/delete/{id}")
    public Result delete(@PathVariable("id") int id){
        return surveyService.delete(id);
    }

    //批量删除
    @PostMapping("/del/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) { // [1,2,3]
        return surveyService.deletes(ids);
    }

    //分页显示（查询）
    @GetMapping("/page")
    public Result findPage(@RequestParam Integer pageNum,
                           @RequestParam Integer pageSize,
                           @RequestParam(defaultValue = "") String name,
                           @RequestParam(defaultValue = "") String content) {
        return surveyService.page(pageNum,pageSize,name,content);
    }

    //根据用户ID查看用户意见反馈列表
    @GetMapping("/id")
    public Result check(@RequestParam Integer page,
                        @RequestParam Integer size,
                        @RequestParam(name = "user_id") Integer id){
        return surveyService.check(page,size,id);
    }

    // 获取反馈详情
    @PostMapping("/detail/{id}")
    public Result detail(@PathVariable("id") int id){
        return surveyService.detail(id);
    }
}
